//
//  ProfileTabHeader.m
//  TenMinDemo
//
//  Created by Shawn Li on 2021/3/8.
//  Copyright © 2021 CYXiang. All rights reserved.
//

#import "ProfileTabHeader.h"
#import "UserInfoModel.h"
#import <UIButton+WebCache.h>
@interface ProfileTabHeader()
@property (weak, nonatomic) IBOutlet UILabel *name;
@property (weak, nonatomic) IBOutlet UILabel *hid;
@property (weak, nonatomic) IBOutlet UILabel *phone;
@property (weak, nonatomic) IBOutlet UIButton *icon;
@property (weak, nonatomic) IBOutlet UIButton *loginBtn;

@end
@implementation ProfileTabHeader

INITFROMXIB

- (void)awakeFromNib{
    [super awakeFromNib];
    [self.loginBtn setTitle:LCLocalString(@"btn_wdl") forState:(UIControlStateNormal)];
}

- (IBAction)headerAction:(UIButton *)sender {
    if (self.actionBlock) {
        self.actionBlock(sender.tag - 1000);
    }
    
}


- (void)refresh{
    BOOL isHasUser = kAppDelegate.curUser && kAppDelegate.curUser.hid.length;
    UserInfoModel *user = kAppDelegate.curUser;
    self.name.text = user.name;
    self.hid.text = [NSString stringWithFormat:@"HID: %@", user.hid];
    if (user.phone.length) {
        self.phone.text = [NSString stringWithFormat:@"%@: %@",LCLocalString(@"mobile"), user.phone];
    }
    
    [self.icon setImage:user.icon ? user.icon : DefaultUserIcon forState:(UIControlStateNormal)];
    
    self.name.hidden = !isHasUser;
    self.hid.hidden = !isHasUser;
    self.phone.hidden = !isHasUser;
    
    [self.loginBtn setTitle:isHasUser ? @"":LCLocalString(@"btn_wdl") forState:(UIControlStateNormal)];
    
}

@end
